package com.ruoyi.system.service.impl;

import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.system.domain.SysPythonAddressEntity;
import com.ruoyi.system.domain.SysPythonEntity;
import com.ruoyi.system.domain.SysPythonEntityDTO;
import com.ruoyi.system.domain.vo.PageVo;
import com.ruoyi.system.mapper.ISysPythonMapper;
import com.ruoyi.system.service.IMpSysPythonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author <a href="https://fengwenyi.com?fs=mpcg">Erwin Feng</a>
 * @since 2024-01-16
 */
@Service
public class MpSysPythonServiceImpl  implements IMpSysPythonService {
    @Autowired
    private ISysPythonMapper iSysPythonMapper;
    @Autowired
    private RedisCache redisCache;

    @Override
    public PageInfo<SysPythonEntity> sysPythonPage(SysPythonEntityDTO sysPythonEntityDTO , PageVo pageVo) {
        int offset = (pageVo.getPageNum() - 1) * pageVo.getPageSize();pageVo.setPageNum(offset);
        Integer sysCount = iSysPythonMapper.selectCounts(sysPythonEntityDTO);
        List<SysPythonEntity> sysPythonEntityIPage = iSysPythonMapper.selectListPage(sysPythonEntityDTO,pageVo);
        List<SysPythonAddressEntity> sysPythonAddressEntities=  redisCache.getCacheList("addressName::");
        sysPythonEntityIPage.forEach(sysPythonEntity -> {
            if (redisCache.getExpire("addressName::")!=-2){
                sysPythonAddressEntities.forEach(sysPythonAddressEntity -> {
                    if (sysPythonEntity.getAddress().equals(sysPythonAddressEntity.getId().toString())) {
                        sysPythonEntity.setAddressName(sysPythonAddressEntity.getAddressName());
                    }
                });
            }
        });
        PageInfo<SysPythonEntity> pageInfo = new PageInfo<>(sysPythonEntityIPage);
        pageInfo.setTotal(sysCount);
        return pageInfo;
    }



}
